package com.fastcms.cms.service.impl;

import static com.fastcms.cms.service.IArticleService.ArticleI18n.CMS_ARTICLE_COMMENT_ARTICLE_ID_NOT_ALLOW_NULL;
import static com.fastcms.cms.service.IArticleService.ArticleI18n.CMS_ARTICLE_COMMENT_CONTENT_IS_NOT_ALLOW_NULL;

import java.time.LocalDateTime;

import javax.validation.constraints.NotNull;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fastcms.cms.entity.Quesstion;
import com.fastcms.cms.mapper.QuesstionMapper;
import com.fastcms.cms.service.IQuesstionService;
import com.fastcms.common.exception.FastcmsException;
import com.fastcms.common.exception.I18nFastcmsException;

/**
 * 文章评论服务实现类
 * @author wjun_java@163.com
 * @since 2021-05-23
 */
@Service
public class QuesstionServiceImpl extends ServiceImpl<QuesstionMapper, Quesstion> implements IQuesstionService {

	@Override
	public Page<Quesstion> pageQuesstion(Page pageParam, QueryWrapper queryWrapper) {
		return getBaseMapper().pageQuesstion(pageParam, queryWrapper);
	}


	@Override
	public void saveQuesstion(@NotNull String categoryId, @NotNull String content, @NotNull String mobile,@NotNull String areaCode) throws FastcmsException {

//		if(categoryId == null) {
//			throw new I18nFastcmsException("提问类型不能为空");
//		}

		if(StringUtils.isBlank(content)) {
			throw new I18nFastcmsException("提问内容不能为空");
		}
		
		if(StringUtils.isBlank(mobile)) {
			throw new I18nFastcmsException("联系方式不能为空");
		}
//		
//		if(StringUtils.isBlank(areaCode)) {
//			throw new I18nFastcmsException("案件区域不能为空");
//		}

		Quesstion quesstion = new Quesstion();
		if(StringUtils.isNotBlank(categoryId)&&StringUtils.isNumeric(categoryId)) {
			quesstion.setCategoryId(Long.valueOf(categoryId));
		}
		quesstion.setContent(content);
		quesstion.setMobile(mobile);
		quesstion.setAreaCode(areaCode);
		quesstion.setCreateTime(LocalDateTime.now());
		quesstion.setUpdateTime(LocalDateTime.now());		

		save(quesstion);
	}

}
